import { Component } from '@angular/core';
import { IonicPage, NavController, ToastController } from 'ionic-angular';
import { Base64Util } from '../../../providers/common/base64Util';
import { loginModel } from '../../../models/login/login.model';
import { ForgetPasswordComponent } from '../forget-password/forget-password';
import { LoadingProvider } from '../../../providers/common/loadingUtil';
import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';

@IonicPage() @Component({
    selector: 'login', templateUrl: 'login.html'
})
export class LoginComponent {


    loginModel: FormGroup;

    // loginModel: loginModel = {
    //     loginName: null, loginPwd: null
    // };

    constructor(private navCtrl: NavController, public formBuilder: FormBuilder, private loadingProvider: LoadingProvider,
                private base64Util: Base64Util, private toastCtrl: ToastController) {
    }

    ionViewWillLoad() {
        this.loginModel = this.formBuilder.group({
            loginName: new FormControl('', Validators.compose([
                Validators.required
            ])),
            loginPwd: new FormControl('', Validators.required)
        });
    }

    /**
     * 登录
     */
    login(value) {
        const params = {
            loginName: this.base64Util.encode(value.loginName), loginPwd: this.base64Util.encode(value.loginPwd)
        };

        // this.loadingProvider.create({
        //     content: '登录中...', dismissOnPageChange: true, duration: 1000
        // }).present();
        // this.loadingProvider.loading('open', '登录中');
        // 跳转
    }

    /**
     * 忘记密码
     */
    forgetPassword() {
        this.navCtrl.push('ForgetPasswordComponent');
    }
}
